package jz.sats.ai;

import jakarta.annotation.Resource;
import jz.sats.rag.QueryRewriter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;


/**
 * @Description: TODO
 * @Author: sats@jz
 * @Date: 2025/8/6 22:17
 **/
@Slf4j
@Component
public class LoveAI {
    @Resource(name = "loveChatClient")
    private ChatClient loveChatClient;


    public String doChat(String message, String chatId) {
        return loveChatClient.prompt()
                .user(message)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, chatId))
                .advisors()
                .call()
                .content();
    }


    public String doChatWithRag(String message, String chatId) {
        return loveChatClient.prompt()
                .user(message)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, chatId))
                .advisors()
                .call()
                .content();
    }
    @Resource
    private ToolCallback[] allTools;

    public String doChatWithTools(String message, String chatId) {
        return loveChatClient.prompt()
                .user(message)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, chatId))
                .advisors()
                .toolCallbacks(allTools)
                .call()
                .chatResponse()
                .getResult()
                .getOutput()
                .getText();
    }

}
